<HTML><HEAD><TITLE>flatten(++MaxDepth, +NestedList, ?FlatList)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">library(lists)</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>flatten(++MaxDepth, +NestedList, ?FlatList)</H1>
Depth-limited list flattening
<DL>
<DT><EM>++MaxDepth</EM></DT>
<DD>Maximum depth to flatten.
</DD>
<DT><EM>+NestedList</EM></DT>
<DD>List.
</DD>
<DT><EM>?FlatList</EM></DT>
<DD>List or variable.
</DD>
</DL>
<H2>Description</H2>
   Like flatten/2, but does not flatten beyond the specified depth MaxDepth.
   So flatten(0, List, Flat) just unifies Flat and List (no flattening),
   flatten(1, List, Flat) just flattens the top-level list of List, etc.
<P>
   This predicate does not perform any type testing functions.
	
<H3>Modes and Determinism</H3><UL>
<LI>flatten(++, +, -) is det
</UL>
<H3>Fail Conditions</H3>
   Fails if FlatList does not unify with the flattened version of
   NestedList.


<H3>Resatisfiable</H3>
   No.
<H2>Examples</H2>
<PRE>
   Success:
      [eclipse]: flatten(0, [[1,2,[3,4],5],6,[7]], L).
      L = [[1, 2, [3, 4], 5], 6, [7]]
      yes.
      [eclipse]: flatten(1, [[1,2,[3,4],5],6,[7]], L).
      L = [1, 2, [3, 4], 5, 6, 7]
      yes.
      [eclipse]: flatten(2, [[1,2,[3,4],5],6,[7]], L).
      L = [1, 2, 3, 4, 5, 6, 7]
      yes.
      [eclipse]: flatten(3, [[1,2,[3,4],5],6,[7]], L).
      L = [1, 2, 3, 4, 5, 6, 7]
      yes.
      
   Fail:
      [eclipse]: flatten(2, [1,[3],2], [1,2,3]).
      no.
</PRE>
<H2>See Also</H2>
<A HREF="../../lib/lists/flatten-2.html">flatten / 2</A>, <A HREF="../../kernel/termcomp/sort-2.html">sort / 2</A>, <A HREF="../../kernel/termcomp/sort-4.html">sort / 4</A>, <A HREF="../../lib/lists/length-2.html">length / 2</A>, <A HREF="../../lib/lists/member-2.html">member / 2</A>
</BODY></HTML>
